const mysql = require("mysql")

let pool = mysql.createPool({
    host: 'localhost',
    user: 'user',
    password: '123456',
    database: 'good-chinese-poetry'
})


function excute(sqlString, condition) {
    let promise = new Promise((resolve, reject) => {
        pool.query(sqlString, condition, function(error, result, fields) {
            if(error) {
                reject(error);
            }
            else {
                resolve(result);
            }
        })
    })
    return promise;
    
}

module.exports = {
    query: (sql,condition) => {
        let p1 = new Promise((resolve, reject) => {
            pool.query(sql, condition,(err, results, fiedls) => {
                if (err) {
                    reject(err)
                } else {
                    resolve(results)
                }
            })
        })
        return p1

    },
    EXCUTE: excute
}